home *** CD-ROM | disk | FTP | other *** search
- ;void delete_all(strg,ch,position);
- ; unsigned char *strg,ch,position;
-
- EXTRN _memory_model:byte
- EXTRN _error_code:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _delete_all
- _delete_all proc near
- mov _error_code,1 ;assume an error will occur
- push bp ;
- mov bp,sp ;set up stack frame
- push di ;
- push si ;
- push ds ;save DS
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- lds si,dword ptr[bp+4] ;DS:SI pts to the string
- inc bp ;add 2 to BP since dword ptr
- inc bp ;
- jmp short L1 ;
- L0: mov si,[bp+4] ;NEAR case
- L1: mov ax,ds ;ES = DS
- mov es,ax ;
- sub cx,cx ;
- mov al,[bp+6] ;get the search char
- mov cl,[bp+8] ;get starting position
- inc cx ;count from 1
- mov dx,cx ;keep a copy
- L2: cmp byte ptr[si],0 ;move si to starting pos
- je L10 ;quit if start is outside string
- inc si ;
- loop L2 ;loop
- cmp [si-1],al ;search char at position?
- jne L10 ;quit if not
- mov di,si ;copy ptr
- mov cx,dx ;search left for character
- L3: dec di ;
- cmp byte ptr[di],al ;search char?
- jne L4 ;quit loop if not
- loop L3 ;loop
- dec di ;cancel effect of next line
- L4: inc di ;
- L5: cmp byte ptr[si],0 ;SI at end of string?
- je L6 ;nothing to search for if so
- inc si ;begin search to right
- mov ah,[si] ;get a char
- cmp ah,0 ;end of string?
- jne L7 ;jump ahead if not
- L6: mov byte ptr[di],0 ;all eliminated to right
- jmp short L9 ;set null and quit
- L7: cmp ah,al ;search char?
- je L5 ;loop if so
- cld ;now transfer down high end of string
- L8: lodsb ;get a char
- stosb ;shift it
- cmp al,0 ;end of string?
- jne L8 ;loop till end
- L9: pop ds ;restore DS
- dec _error_code ;no error
- jmp short L11 ;jump ahead
- L10: pop ds ;error case
- L11: pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _delete_all ENDP
- _TEXT ENDS
- END